<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>001操作元素</title>
    <script type="text/javascript">
        window.onload = function() {
            var oDiv = document.getElementById('div1');
            var oA = document.getElementById('link');

            // 读取属性
            var sId = oDiv.id;
            alert(sId);

            // 写属性
            oDiv.style.color = "green";
            oA.href = 'http://www.baidu.com';
            oA.title = "this is link to baidu";

        }
    </script>
</head>
<body>
    <div id="div1">
        this is a div
    </div>
    <a href="#" id="link">this is a link </a>
</body>
</html>